import 'package:bxultimate/domain/application/organization/AttendanceClockResultDto.dart';
import 'package:bxultimate/domain/application/organization/AttendanceDayStatistics.dart';
import 'package:bxultimate/domain/application/organization/AttendanceItemDto.dart';
import 'package:bxultimate/domain/application/organization/AttendanceMyCreateDto.dart';
import 'package:bxultimate/domain/application/organization/AttendanceTypeDto.dart';
import 'package:bxultimate/domain/application/organization/AttendanceUserDto.dart';
import 'package:bxultimate/domain/application/organization/AttendanceYearStatistics.dart';
import 'package:bxultimate/domain/application/organization/ChatDto.dart';
import 'package:bxultimate/domain/application/organization/ChatRoomInfoDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationAnnouncementAnalysisDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationAnnouncementAnalysisUserDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationAnnouncementItemDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationAnnouncementTaskDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationAnnouncementTemplateDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationApplyRecordDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationApproveItemDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationCheckPointDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationInfoDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationStatisticsTaskItemDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationTypeDto.dart';
import 'package:bxultimate/domain/application/organization/OrganizationUserInfoDto.dart';
import 'package:bxultimate/domain/application/organization/PersonAttendanceClickingDto.dart';
import 'package:bxultimate/domain/common/result.dart';
import 'package:bxultimate/shared/util/util_http.dart';

class OrganizationRequest {
  static Future<List<OrganizationDto>> getOrganizationList() async {
    var response = await UtilHttp().get(
      '/app/andriod/team/teamList',
    );
    return response['data']
        .map<OrganizationDto>((item) => OrganizationDto.fromJson(item))
        .toList();
  }

  // 聊天室信息
  static Future<ChatRoomInfoDto> getChatRoom(
      orgId, attributionCode, areaLsgx) async {
    var response = await UtilHttp().get(
      '/app/chatRoom/getChatRoom?teamId=${orgId}&attributionCode=${attributionCode}&areaLsgx=${areaLsgx}',
    );
    return ChatRoomInfoDto.fromJson(response['data']);
  }
  // 聊天室
  static Future<List<ChatDto>> getRecordList(
      page,pageSize,chatRoomId) async {
    var response = await UtilHttp().get(
      '/app/chatRecord/getRecordList?pageNumber=${page}&pageSize=${pageSize}&chatRoomId=${chatRoomId}',
    );
    return response['data']['records']
        .map<ChatDto>((item) => ChatDto.fromJson(item))
        .toList();
  }

  // 审批列表
  static Future<List<OrganizationApproveItemDto>> getApprovalPage(
      String teamId, int page, int size, String status) async {
    var response = await UtilHttp().get(
      '/app/andriod/approval/getApprovalPage?teamId=${teamId}&selectType=${status}&pageNumber=${page}&pageSize=${size}',
    );
    return response['data']['records']
        .map<OrganizationApproveItemDto>(
            (item) => OrganizationApproveItemDto.fromJson(item))
        .toList();
  }

  // 审批详情
  static Future<OrganizationApproveItemDto> getAdjustRecordEvents(
      recordId) async {
    var response = await UtilHttp().get(
      '/app/andriod/approval/getAdjustRecordEvents?recordId=${recordId}',
    );
    return OrganizationApproveItemDto.fromJson(response['data']);
  }

  // 提交审批
  static Future<Result> submitApprove(data) async {
    var response = await UtilHttp()
        .post('/app/andriod/approval/submitApprove', data: data);
    return Result.fromJson(response);
  }

  // 获取队伍信息
  static Future<OrganizationInfoDto> getTeamInfo(id, attributeCode) async {
    var response = await UtilHttp().get(
        '/app/andriod/team/getTeamInfo?teamId=${id}&type=${attributeCode}');
    return OrganizationInfoDto.fromJson(response['data']);
  }

  // 获取是否是管理员
  static Future<Result> getUserTeamRole(id) async {
    var response =
        await UtilHttp().get('/app/andriod/team/getUserTeamRole?teamId=${id}');
    return Result.fromJson(response);
  }

  // 获取队伍成员信息
  static Future<OrganizationUserInfoDto> getTeamUserInfo(idcard, teamId) async {
    var response = await UtilHttp().get(
        '/app/andriod/team/getTeamUserInfo?idcard=${idcard}&role=1&teamId=${teamId}');
    return OrganizationUserInfoDto.fromJson(response['data']);
  }

  // 解散队伍
  static Future<Result> deleteTeam(teamId) async {
    var response =
        await UtilHttp().get('/app/andriod/team/deleteTeam?teamId=${teamId}');
    return Result.fromJson(response);
  }

  // 检查身份
  static Future<Result> checkIsSuperTeamSoleAdmin(teamId) async {
    var response =
        await UtilHttp().get('/business/teamUser/checkIsSuperTeamSoleAdmin?teamId=${teamId}');
    return Result.fromJson(response);
  }

  // 更新用户定位
  static Future<Result> updateUserPosition(lat, lon) async {
    var response = await UtilHttp()
        .get('/app/andriod/user/updateUserPosition?lon=${lon}&lat=${lat}');
    return Result.fromJson(response);
  }

  // 获取卡口列表
  static Future<List<OrganizationCheckPointDto>> getAllCheckPoint() async {
    var response = await UtilHttp().get('/business/checkPoint');
    return response['data']['records']
        .map<OrganizationCheckPointDto>(
            (item) => OrganizationCheckPointDto.fromJson(item))
        .toList();
  }

  // 获取卡口详情
  static Future<OrganizationCheckPointDto> getAllCheckPointDetail(id) async {
    var response = await UtilHttp().get('/business/checkPoint/' + id);
    return OrganizationCheckPointDto.fromJson(response['data']);
  }

  // 获取公告列表
  static Future<List<OrganizationAnnouncementItemDto>> getAnnouncementList(
      String teamId, int page, int size, String type) async {
    var response = await UtilHttp().get(
      '/app/groupNotice/getList?chatRoomId=${teamId}&type=${type}&pageNumber=${page}&pageSize=${size}',
    );
    return response['data']['records']
        .map<OrganizationAnnouncementItemDto>(
            (item) => OrganizationAnnouncementItemDto.fromJson(item))
        .toList();
  }

  // 获取公告详情
  static Future<OrganizationAnnouncementItemDto> getAnnouncementDetail(
      String id) async {
    var response = await UtilHttp().get(
      '/app/groupNotice/getAnnouncementInfo?id=${id}',
    );
    return OrganizationAnnouncementItemDto.fromJson(response['data']);
  }

  // 发布公告
  static Future<Result> appSendAnnouncement(data) async {
    var response = await UtilHttp().post('/app/groupNotice/create', data: data);
    return Result.fromJson(response);
  }

  // 获取我的考勤列表
  static Future<List<PersonAttendanceClickingDto>>
      getPersonAttendanceClockingList(teamId) async {
    var response = await UtilHttp().get(
        '/app/andriod/attendanceClocking/getPersonAttendanceClockingList?teamId=' +
            teamId);
    return response['data']
        .map<PersonAttendanceClickingDto>(
            (item) => PersonAttendanceClickingDto.fromJson(item))
        .toList();
  }

  // 获取考勤详情
  static Future<AttendanceItemDto> getAttendanceClockingDetail(id) async {
    var response = await UtilHttp()
        .get('/app/andriod/attendanceClocking/getDetail?id=' + id);
    return AttendanceItemDto.fromJson(response['data']);
  }

  //获取考勤统计
  static Future<List<AttendanceUserDto>> getClockingRecordsList(
      id, type, date) async {
    var response = await UtilHttp().get(
        '/app/andriod/attendanceClocking/getClockingRecordsList?clockingId=${id}&type=${type}&date=${date}');
    return response['data']
        .map<AttendanceUserDto>((item) => AttendanceUserDto.fromJson(item))
        .toList();
  }

  // 获取是否能打卡
  static Future<AttendanceClockResultDto>
      getAttendanceClockingAroundAndTimeResult(id, lat, lon) async {
    var response = await UtilHttp().get(
        '/app/andriod/attendanceClocking/getAttendanceClockingAroundAndTimeResult?clockingId=${id}&lon=${lon}&lat=${lat}');
    return AttendanceClockResultDto.fromJson(response['data']);
  }

  // 签到
  static Future<Result> addClocking(data) async {
    var response = await UtilHttp()
        .post('/app/andriod/attendanceClocking/addClocking', data: data);
    return Result.fromJson(response);
  }

  // 获取打卡方式
  static Future<List<AttendanceTypeDto>> getAttendanceType() async {
    var response = await UtilHttp().get('/common/sysDictData/attendance_type');
    return response['data']
        .map<AttendanceTypeDto>((item) => AttendanceTypeDto.fromJson(item))
        .toList();
  }

  // 获取统计人员列表
  static Future<List<OrganizationUserInfoDto>> getStatisticsTaskMemberList(
      teamId) async {
    var response = await UtilHttp().get(
        '/app/andriod/statisticsTask/getStatisticsTaskMemberList?teamId=' +
            teamId);
    return response['data']
        .map<OrganizationUserInfoDto>(
            (item) => OrganizationUserInfoDto.fromJson(item))
        .toList();
  }

  // 获取普通成员列表
  static Future<List<OrganizationUserInfoDto>> getCommonMemberList(
      teamId) async {
    var response = await UtilHttp()
        .get('/app/andriod/team/getCommonMemberList?teamId=' + teamId);
    return response['data']
        .map<OrganizationUserInfoDto>(
            (item) => OrganizationUserInfoDto.fromJson(item))
        .toList();
  }

// 转让负责人
  static Future<Result> transferMemberRole(teamId, idcard) async {
    var response = await UtilHttp().get(
        '/app/andriod/team/transferMemberRole?teamId=${teamId}&newIdcard=${idcard}');
    return Result.fromJson(response);
  }

  // 个人考勤按月份统计
  static Future<List<AttendanceYearStatistics>> getPersonStatisticsByMonth(
      id, date) async {
    var response = await UtilHttp().get(
        '/app/andriod/attendanceClocking/getPersonStatisticsByMonth?clockingId=${id}&date=${date}');
    return response['data']
        .map<AttendanceYearStatistics>(
            (item) => AttendanceYearStatistics.fromJson(item))
        .toList();
  }

  // 个人考勤按天统计
  static Future<List<AttendanceDayStatistics>> getPersonStatisticsByDay(
      id, date) async {
    var response = await UtilHttp().get(
        '/app/andriod/attendanceClocking/getPersonStatisticsByDay?clockingId=${id}&date=${date}');
    return response['data']
        .map<AttendanceDayStatistics>(
            (item) => AttendanceDayStatistics.fromJson(item))
        .toList();
  }

  // 创建考勤
  static Future<Result> createAttendanceClocking(data) async {
    var response = await UtilHttp()
        .post('/app/andriod/attendanceClocking/create', data: data);
    return Result.fromJson(response['data']);
  }

  // 我创建的考勤
  static Future<List<AttendanceMyCreateDto>>
      getCreateAttendanceClockingPageList(int page, int size) async {
    var response = await UtilHttp().get(
      '/app/andriod/attendanceClocking/getCreateAttendanceClockingPageList?pageNumber=${page}&pageSize=${size}',
    );
    return response['data']['records']
        .map<AttendanceMyCreateDto>(
            (item) => AttendanceMyCreateDto.fromJson(item))
        .toList();
  }

  // 删除考勤
  static Future<Result> deleteAttendanceClocking(id) async {
    var response = await UtilHttp().get(
      '/app/andriod/attendanceClocking/delete?id=' + id,
    );
    return Result.fromJson(response);
  }

  // 统计 start

  // 统计任务列表
  static Future<List<OrganizationStatisticsTaskItemDto>> getStatisticsTaskList(
      String teamId, int page, int size, String type) async {
    var response = await UtilHttp().get(
      '/app/andriod/statisticsTask/getStatisticsTaskList?teamId=${teamId}&type=${type}&pageNumber=${page}&pageSize=${size}',
    );
    return response['data']['records']
        .map<OrganizationStatisticsTaskItemDto>(
            (item) => OrganizationStatisticsTaskItemDto.fromJson(item))
        .toList();
  }

  // 获取模板列表
  static Future<List<OrganizationAnnouncementTemplateDto>>
      getStatisticsTaskTeamplateList(int page, int size) async {
    var response = await UtilHttp().get(
      '/app/andriod/statisticsTask/getStatisticsTaskTeamplateList?pageNumber=${page}&pageSize=${size}',
    );
    return response['data']['records']
        .map<OrganizationAnnouncementTemplateDto>(
            (item) => OrganizationAnnouncementTemplateDto.fromJson(item))
        .toList();
  }

  // 删除模板
  static Future<Result> deleteTemplate(String id) async {
    var response = await UtilHttp().get(
      '/app/andriod/statisticsTask/deleteTemplate?id=' + id,
    );
    return Result.fromJson(response);
  }

  // 创建或修改考勤
  static Future<Result> insertOrUpdateTemplate(data) async {
    var response = await UtilHttp()
        .post('/app/andriod/statisticsTask/insertOrUpdateTemplate', data: data);
    return Result.fromJson(response);
  }

  // 获取模板详情
  static Future<OrganizationAnnouncementTemplateDto>
      getStatisticsTaskTeamplateInfo(id) async {
    var response = await UtilHttp().get(
        '/app/andriod/statisticsTask/getStatisticsTaskTeamplateInfo?id=' + id);
    return OrganizationAnnouncementTemplateDto.fromJson(response['data']);
  }

  // 创建任务
  static Future<Result> insertStatisticsTask(data) async {
    var response = await UtilHttp()
        .post('/app/andriod/statisticsTask/insertStatisticsTask', data: data);
    return Result.fromJson(response);
  }

  // 获取任务详情
  static Future<OrganizationAnnouncementTaskDto> getMyReceiveStatisticsTaskInfo(
      id) async {
    var response = await UtilHttp().get(
        '/app/andriod/statisticsTask/getMyReceiveStatisticsTaskInfo?tssId=' +
            id);
    return OrganizationAnnouncementTaskDto.fromJson(response['data']);
  }

  // 提交任务
  static Future<Result> submitStatisticsTask(data) async {
    var response = await UtilHttp()
        .post('/app/andriod/statisticsTask/submitStatisticsTask', data: data);
    return Result.fromJson(response);
  }

  // 我发出的任务统计
  static Future<OrganizationAnnouncementAnalysisDto>
      getMySendStatisticsTaskInfo(id) async {
    var response = await UtilHttp().get(
        '/app/andriod/statisticsTask/getMySendStatisticsTaskInfo?id=' + id);
    return OrganizationAnnouncementAnalysisDto.fromJson(response['data']);
  }

  // 获取统计完成人员
  static Future<List<OrganizationAnnouncementAnalysisUserDto>>
      getMySendStatisticsTaskStatusMemberList(id, status) async {
    var response = await UtilHttp().get(
        '/app/andriod/statisticsTask/getMySendStatisticsTaskStatusMemberList?id=${id}&status=${status}');
    return response['data']
        .map<OrganizationAnnouncementAnalysisUserDto>(
            (item) => OrganizationAnnouncementAnalysisUserDto.fromJson(item))
        .toList();
  }

  // 导出
  static Future<Result> exportCompleteTask(id) async {
    var response = await UtilHttp().get(
        '/app/appTask/exportCompleteTask?taskId=${id}&type=allCount&taskType=');
    return Result.fromJson(response);
  }

  // 统计 end

  // 获取队伍类型
  static Future<List<OrganizationTypeDto>> getTeamTypeList(pid) async {
    var response = await UtilHttp()
        .get('/app/andriod/team/getTeamTypeList?pid=${pid}&type=app');
    return response['data']
        .map<OrganizationTypeDto>((item) => OrganizationTypeDto.fromJson(item))
        .toList();
  }

  // 获取推荐队伍
  static Future<List<OrganizationDto>> recommendationTeam(
      lat, lon, keyword) async {
    var response = await UtilHttp().get(
        '/app/andriod/team/recommendationTeam?pageNumber=1&pageSize=5&lon=${lon}&lat=${lat}&condition=${keyword}');
    return response['data']['records']
        .map<OrganizationDto>((item) => OrganizationDto.fromJson(item))
        .toList();
  }

  // 创建队伍
  static Future<Result> createTeam(data) async {
    var response =
        await UtilHttp().post('/app/andriod/team/createTeam', data: data);
    return Result.fromJson(response);
  }

  // 申请记录
  static Future<List<OrganizationApplyRecordDto>> getApplyRecordList(
      page, size) async {
    var response = await UtilHttp().get(
        '/app/andriod/approval/getApplyRecordList?pageNumber=${page}&pageSize=${size}');
    return response['data']['records']
        .map<OrganizationApplyRecordDto>(
            (item) => OrganizationApplyRecordDto.fromJson(item))
        .toList();
  }
}
